#!/bin/bash

logs_path="/app/nginx_logs"

host_name="8166_ 8237_ 8141_ di.imeeta.com_ 8087_ 8109_ 8167_ 8210_ 8139_ 8168_ 8170_ 8237_ 8159_ 8162_ 8212_ 8091_ 8099_ 8111_ 8140_ 8142_ 8143_ 8144_ 8171_ 8172_"
lasthour=`date -d last-hour +%H`
lasthour_Ym=`date -d last-hour +%Y%m`
lasthour_Ymd=`date -d last-hour +%Y%m%d`
for i in ${host_name} ; do
  /bin/mkdir -p ${logs_path}/${lasthour_Ym}/${lasthour_Ymd}/
  /bin/mv ${logs_path}/${i}access.log ${logs_path}/${lasthour_Ym}/${lasthour_Ymd}/${i}access_${lasthour_Ymd}-${lasthour}.log
done
#  /bin/rm -f ${logs_path}/stat_access.log

cuthour=$(date +%H)
if [ "${cuthour}" -eq "00" ]; then
  for i in ${host_name} ; do
    /bin/mkdir -p ${logs_path}/${lasthour_Ym}/${lasthour_Ymd}/
    /bin/mv ${logs_path}/${i}abnormal_access.log ${logs_path}/${lasthour_Ym}/${lasthour_Ymd}/${i}abnormal_access_${lasthour_Ymd}.log
    /bin/mv ${logs_path}/${i}abnormal5xx_access.log ${logs_path}/${lasthour_Ym}/${lasthour_Ymd}/${i}abnormal5xx_access_${lasthour_Ymd}.log
    /bin/mv ${logs_path}/nginx_error.log ${logs_path}/${lasthour_Ym}/${lasthour_Ymd}/nginx_error_${lasthour_Ymd}.log
  done
fi

#/bin/kill -USR1 `cat /app/openresty/nginx/logs/nginx.pid`
/usr/sbin/nginx -s reload
